﻿using System.Collections.Generic;

namespace WeixinSDK.Message
{
    /// <summary>
    /// 回复图文消息
    /// </summary>
    [System.Xml.Serialization.XmlRoot("Articles")]
    public class ResNews : ResData, IEnumerable<ResArtical>
    {
        public ResNews()
        {
            Articles = new List<ResArtical>();
        }

        /// <summary>
        /// [必需]图文消息个数，限制为10条以内
        /// </summary>
        public int ArticleCount
        {
            get { return Articles.Count; }
        }

        public override WxMsgType MsgType
        {
            get { return WxMsgType.news; }
        }

        /// <summary>
        /// [必需]多条图文消息信息，默认第一个item为大图,注意，如果图文数超过10，则将会无响应
        /// </summary>
        [System.Xml.Serialization.XmlIgnore]
        public List<ResArtical> Articles { get; private set; }

        public void Add(ResArtical artical)
        {
            if (artical == null)
                throw new System.ArgumentNullException("artical");

            Articles.Add(artical);
        }

        public IEnumerator<ResArtical> GetEnumerator()
        {
            return Articles.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return Articles.GetEnumerator();
        }
    }

    /// <summary>
    /// 用于回复图文消息
    /// </summary>
    [System.Xml.Serialization.XmlType("item")]
    public class ResArtical
    {
        /// <summary>
        /// [可选]图文消息标题
        /// </summary>
        public CData Title { get; set; }
        /// <summary>
        ///  [可选]图文消息描述
        /// </summary>
        public CData Description { get; set; }
        /// <summary>
        /// [可选]图片链接，支持JPG、PNG格式，较好的效果为大图360*200，小图200*200
        /// </summary>
        public CData PicUrl { get; set; }
        /// <summary>
        /// [可选] 点击图文消息跳转链接
        /// </summary>
        public CData Url { get; set; }
    }
}
